window.icons = {
    refresh: 'bx bx-sync',
    columns: 'bx bx-list-ul',
    toggleOn: 'bx bx-toggle-right',
    toggleOff: 'bx bx-toggle-left',
    fullscreen: 'bx bx-expand'
}
var tipJson = [{
    image:"https://file.tiantianwailian.com/images/qrcodetip.jpg",
    name:'子二维码管理',
    content:'管理子二维码码,包含子码的添加、更新、删除等操作！至少上传一个子码才能复制链接！',
    cssname:'qrcode'
},{
    image:"https://file.tiantianwailian.com/images/copyurltip.jpg",
    name:'复制推广链接',
    content:'上传好子二维码后，可以点击此项复制链接，可复制链接、可预览二维码、可复制自定义渠道码的链接！',
    cssname:'copy'
},{
    image:"https://file.tiantianwailian.com/images/basictip.jpg",
    name:'链接基本信息',
    content:'客服链接基本信息，此项包含整个客服链接的基本信息，可在此项修改备注',
    cssname:'basic'
},{
    image:"https://file.tiantianwailian.com/images/recordtip.jpg",
    name:'完整访问记录',
    content:'访问记录完整展示，可详细展示用户是否点击链接，是否发送欢迎语，是否长按识别等数据！',
    cssname:'record'
}];

var $table = $('#qrcode-image');
var $tableRecord = $("#recode-lists");
var kfQrcodes = [];
var imagearr = [];
var kfRecordLists = [];
var kfTotalData = {};
var linkDetialLoad = { "record": 1, "chart": 1, "other": 1 };
var nextRecordData = { "total": "", "total_end": "", "total_start": "" };

$(document).ready(function(){
    var copylink = new ClipboardJS('#copylink');
    copylink.on('success', function(e) {
        var noticetext = $("#copylink").attr("text");
        mviewToastr("success",noticetext+"复制成功，粘贴即可获取!");
    });

    var copyurl = new ClipboardJS('#copy-url', {
        container: document.getElementById('qudaoModal')
    });
    copyurl.on('success', function(e) {
        var noticetext = $("#copy-url").attr("text");
        mviewToastr("success",noticetext+"复制成功，粘贴即可获取!");
    });

    if($('#kfid').val){
        kfTotalStatistic();
        $("#record_data_end").val(moment().format("YYYY-MM-DD 23:59:59")); 
    }

    var itemnum;
    $("#linkDetialTable li").click(function() {
        var value = $(this).attr('data');
        if(itemnum== value){
            return;
        }
        itemnum = value;
        $("#linkDetialTable li").removeClass("active");
        $(this).addClass("active");
        $(".data-qrcode").hide();
        $(".data-chart").hide();
        $(".data-record").hide();
        $(".data-other").hide();
        $(".data-total").hide();
        $(".data-basic").hide();
        $(".data-copy").hide();
        $(".data-" + value).show();
        if (value == "qrcode") {

        } else if (value == "chart") {
            if (linkDetialLoad.chart == 1) {
                linkDetialLoad.chart = 2;
                statisticsDate('threeday');
            }else{
                var chartDom = document.getElementById('overview-chart');
                var myChart = echarts.init(chartDom);
                myChart.resize();
            }
        } else if (value == "total") {
            getTotalChart();
        } else if (value == "record") {
            if (linkDetialLoad.record == 1) {
                linkDetialLoad.record = 2;
                kfRecordReload();
            }
        } else if (value == "other") {
            if (linkDetialLoad.other == 1) {
                linkDetialLoad.other = 2;
                renderOtherData("thismonth");
            }else{
                renderOtherData("thismonth");
            }
        }else if(value == "basic"){

        }
    });
    $("#record_data_end").val(moment().format("YYYY-MM-DD 23:59:59"));

    $("#otherDateTime li").click(function() {
        $("#otherDateTime li").removeClass("active");
        $(this).addClass("active");
        var value = $(this).attr('data');
        renderOtherData(value);
    });

    $("#otherChartType li").click(function() {
        $("#otherChartType li").removeClass("active");
        $(this).addClass("active");
        var value = $(this).attr('data');
        $("#other_chart").val(value);
        renderOtherChart();
    });
    $("#recordExportDate li").click(function() {
        $("#recordExportDate li").removeClass("active");
        $(this).addClass("active");
        var value = $(this).attr('data');
        renderRecordExportTime(value);
    });

    $("#url_type_row li").click(function() {
        var value = $(this).attr('data');
        $("#url_type_row li").removeClass("active");
        $(this).addClass("active");
        $("#url_type").val(value);
        if(value == 1){
            $("#preview_qrcode").show();
            $("#back_setting").hide();
            $("#links_callback_row").hide();
        } else {
            $("#preview_qrcode").hide();
            $("#back_setting").show();
            $("#links_callback_row").show();
        }
        renderBackPlatfrom("dy");
    })
    $("#back_platfrom_lists li").click(function() {
        var platfrom = $(this).attr('data');
        if(platfrom == "more"){
           mviewToastr("warning","正在开发中,感谢您的支持!");
           return;
        }
        renderBackPlatfrom(platfrom);
    })
});

function renderBackPlatfrom(platfrom) {
    var backPlatfroms = JSON.parse($("#backPlatfroms").val());
    var url_type = $("#url_type").val();
    if (url_type == 2) {
        if ($.inArray(platfrom,backPlatfroms) === -1) {
            $("#copyLinkBtn").hide();
            $("#copyLinkQudao").hide();
        } else {
            $("#copyLinkBtn").show();
            $("#copyLinkQudao").show();
        }
    } else {
        $("#copyLinkBtn").show();
        $("#copyLinkQudao").show();
    }
    $("#back_platfrom_lists li").removeClass("active");
    $("#back_platfrom_lists li[data="+platfrom+"]").addClass("active");
    $("#back_platfrom").val(platfrom);
}

function backSetting() {
    var back_platfrom = $("#back_platfrom").val();
    var kfid = $("#kfid").val();
    var product_id = $("#product_id").val();
    if (product_id < 4) {
        mviewToastr("error","仅旗舰版会员支持广告回传,请开通旗舰版会员后使用!");
        return;
    }
    window.location.href = "/admin/wxkf/work_link_back/"+kfid+"/"+back_platfrom;
}

function qrcodeListReload() {
    $table.bootstrapTable('refresh');
}

function kfRecordReload() {
    $tableRecord.bootstrapTable('refresh');
}

function confirmMviewNotification() {
    var mviewNotificationData = JSON.parse($("#mviewNotificationData").val());
    colseMviewNotification();
    if (mviewNotificationData.type == "crop_delete") {
        deleteWxkfCrop(mviewNotificationData.corp_id);
    } else if (mviewNotificationData.type == "link_delete") {
        deleteWorkLink(mviewNotificationData.kfid,mviewNotificationData.page);
    } else if (mviewNotificationData.type == "qecodedelete") {
        deleteKfQrcode(mviewNotificationData.qrcodes_id);
    }
}

// 获取详情总访问数据
function kfTotalStatistic() {
    var kfid = $("#kfid").val();
    var users_id = $("#users_id").val();
    $.ajax({
        url: "/admin/wxkf/wxkf_total_statistic",
        data: {
            "kfid": kfid,
            "users_id": users_id,
        },
        success: function(result) {
            if (result.status == "error") {
                mviewToastr("error", result.msg);
            } else {
                kfTotalData = result.data;
                $("#today_web").text(kfTotalData.todayStatic.web + "次");
                $("#today_kefu").text(kfTotalData.todayStatic.kefu + "人");
                $("#today_qrcode_show").text(kfTotalData.todayStatic.qrcode_show + "人");
                $("#today_qrcode_press").text(kfTotalData.todayStatic.qrcode_press + "人");
            }
        },
        error: function(error) {
            mviewToastr("error", "请求失败,请联系客服处理！");
        }
    });
}

function getTotalChart() {
    var chartDom = document.getElementById('totalChart');
    var myChart = echarts.init(chartDom);
    var dataLists = [];

    var colorLists = ['#5470c6','#5470c6','#fac858','#91cc75', '#ee6666', '#73c0de', '#3ba272', '#fc8452', '#9a60b4', '#ea7ccc'];
    var colorIndex = 0;
    var platfrom_type = parseInt($("#platfrom_type").val());
    $.each(kfTotalData.totalStatic, function(key, linkTotal) {
        dataLists.push({"value":linkTotal+parseInt(kfTotalData.todayStatic[key]),"itemStyle":{"color":colorLists[colorIndex]}});
        colorIndex += 1;
    });
    var datakey = ['链接访问量', '跳客服按钮点击', '客服发送', '二维码展示', '二维码长按识别', '点击名片'];
    var option = {
        title: {
            text: '累计访问数据',
            subtext: "点击名片数量为长按二维码后5秒隐藏页面事件",
            x: 'left'
        },
        color: ['#5470c6', '#91cc75', '#fac858', '#ee6666', '#73c0de', '#3ba272', '#fc8452', '#9a60b4', '#ea7ccc'],
        yAxis: {
            type: 'category',
            data: datakey
        },
        xAxis: {
            type: 'value'
        },
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'cross',
                label: {
                    backgroundColor: '#6a7985',
                    precision: 0
                }
            }
        },
        toolbox: {
            feature: {
                saveAsImage: {
                    type: 'png',
                    title: '下载累计访问数据',
                    name: '累计访问数据'
                }
            }
        },
        series: [{
            data: dataLists,
            type: 'bar',
            showBackground: true,
            backgroundStyle: {
                color: 'rgba(180, 180, 180, 0.2)'
            }
        }]
    };
    myChart.setOption(option);
}

function qudaoshow() {
    $("#qudaoModal .modal-self-header h3").text("添加渠道码");
    $("#qudaoModal").modal('toggle');
}

function hideqrcodeurl() {
    $("#qrcode-url-content").css('display', 'none');
    $("#qrcode-mask").hide();
}

function copyWxkfUrl(status) {
    var url_type = $("#url_type").val();
    var kfid = $("#kfid").val();
    if (url_type == 1) {
        var kfurl = "https://kf.pdb2.com/kf/"+kfid;
        if (status == 2) {
            var channel_code = $("#channel_code").val();
            if (channel_code != "") {
                kfurl = kfurl+'?code='+channel_code;
            }
        }
        $("#copylink").attr("data-clipboard-text",kfurl);
        $("#copylink").attr("text","通用链接");
    } else {
        var back_platfrom = $("#back_platfrom").val();
        var kfurl = "https://kf.pdb2.com/kf/"+kfid+"?back_platfrom="+back_platfrom;
        if (status == 2) {
            var channel_code = $("#channel_code").val();
            if (channel_code != "") {
                kfurl = kfurl+'&code='+channel_code;
            }
        }
        var platfromLists = {"dy":"抖音","bd":"百度"};
        $("#copylink").attr("data-clipboard-text",kfurl);
        $("#copylink").attr("text",platfromLists[back_platfrom]+"链接");
    }
    if (status == 2) {
        $("#qudaoModal").modal("toggle");
    }
    setTimeout(function() {
        $("#copylink").click();
    },300);
}

function previewQrcode(status){
    var url_type = $("#url_type").val();
    var kfid = $("#kfid").val();
    if (url_type == 1) {
        var kfurl = "https://kf.pdb2.com/kf/"+kfid;
        if (status == 2) {
            var channel_code = $("#channel_code").val();
            if (channel_code != "") {
                kfurl = kfurl+'?code='+channel_code;
            }
        }
    } else {
        var back_platfrom = $("#back_platfrom").val();
        var kfurl = "https://kf.pdb2.com/kf/"+kfid+"?back_platfrom="+back_platfrom;
        if (status == 2) {
            var channel_code = $("#channel_code").val();
            if (channel_code != "") {
                kfurl = kfurl+'&code='+channel_code;
            }
        }
        var platfromLists = {"dy":"抖音","bd":"百度"};
    }
    $("#preview-qrcode").html("");
    var qrcode = new QRCode(document.getElementById("preview-qrcode"), {
        text: kfurl,
        width: 500,
        height: 500,
        colorDark: "#000000",
        colorLight: "#ffffff",
        correctLevel: QRCode.CorrectLevel.H
    });
    $("#qrcode-url-content font").text('二维码预览');
    $("#qrcode-url-des").text('请用手机浏览器扫码体验，如需下载，请鼠标右键保存到本地。');
    setTimeout(() => {
        $("#qrcode-mask").show();
        $("#qrcode-url-content").css('display', 'flex');
    },100);
}

function commonQrcode(){
    var kfid = $("#kfid").val();
    var kfurl = "https://kf.pdb2.com/kf/"+kfid;
    $("#pre-qrcode").html("");
    var qrcode = new QRCode(document.getElementById("pre-qrcode"), {
        text: kfurl,
        width: 400,
        height: 400,
        colorDark: "#000000",
        colorLight: "#ffffff",
        correctLevel: QRCode.CorrectLevel.H
    });
    setTimeout(() => {
        $("#preModal").modal('toggle');
    }, 50)
}

function wxkfCropDetial() {
    mviewToastr("warning","功能正在开发中,请耐心等待!");
}

function deleteWxkfCrop(corp_id) {
    $.ajax({
        "url": "/admin/wxkf/wxkf_crop_del",
        "type": "GET",
        "data": {"corp_id":corp_id},
        success: function(res){
            if (res.status == "success") {
                mviewToastr("success",res.msg);
                $("#corp_"+corp_id).remove();
            } else {
                if (res.code == 1005) {
                    setTimeout(function() {
                        window.open("https://moreqifu.com/blog/a/196");
                    },2000);
                }
                mviewToastr("error",res.msg,5);
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            mviewToastr("error","网页错误,请稍后尝试!");
        }
    });
}

function deleteWorkLink(kfid,page) {
    $.ajax({
        "url": "/admin/wxkf/work_link_del",
        "type": "GET",
        "data": {"kfid":kfid},
        success: function(res){
            if (res.status == "success") {
                mviewToastr("success",res.msg);
                if(page == 'details'){
                    setTimeout(()=>{
                        location.href = "/admin/wxkf/wxkf_list"
                    },1000)
                }else{
                    $("#link_"+kfid).remove();
                }
            } else {
                mviewToastr("error",res.msg,5);
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            mviewToastr("error","网页错误,请稍后尝试!");
        }
    });
}

function updateWxkfLinkRemark(kfid) {
    $("#kfid").val(kfid);
    var remark = $("#remark_"+kfid).text();
    $("#remark").val(remark);
    $("#remarkModal").modal("toggle");
}

function wxkfLinkRemarkUpdateSubmit() {
    var kfid = $("#kfid").val();
    var remark = $("#remark").val();
    $.ajax({
        "url": "/admin/wxkf/work_link_remark",
        "type": "GET",
        "data": {"kfid":kfid,"remark":remark},
        success: function(res){
            if (res.status == "success") {
                mviewToastr("success",res.msg);
                $("#remark_"+kfid).text(remark);
                $("#remarkModal").modal("toggle");
            } else {
                mviewToastr("error",res.msg,5);
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            mviewToastr("error","网页错误,请稍后尝试!");
        }
    });
}

function loadingTemplate(message) {
    return '<div style="font-size:14px;display: flex;align-items: center;flex-direction: row;"><i class="bx bx-loader-alt bx-spin me-2"></i>数据加载中,请稍等...</div>'
}

function kfQrcodeLists(params){
    params.data.name = $("#qrcode_name").val();
    params.data.users_id = $("#users_id").val();
    params.data.sign = $("#sign").val();
    params.data.kfid = $("#kfid").val();
    params.data.page = Number(params.data.offset / params.data.limit) + 1;
    $.ajax({
        url: '/admin/wxkf/wxkf_qrcodes',
        data: params.data,
        success: function(result) {
            if (result.status == "success") {
                if (result.data.data.total == 0 && $("#qrcode_name").val() == '' && localStorage.getItem("tip")) {
                    qrcodesListsAllImagesAdd();
                }
                var kfqrcodeLists = [];
                kfQrcodes = [];
                $.each(result.data.data.data, function(key, kfqrcode) {
                    kfQrcodes.push(kfqrcode);
                    var expirationTime = moment(kfqrcode.expiration_time * 1000).format("YYYY/MM/DD");
                    var show_status = getKfQrcodeStatus(kfqrcode);
                    var kfqrcodeList = { "name": kfqrcode.name, "rate": kfqrcode.rate, "expiration_time": expirationTime, "count_limit": kfqrcode.count_limit, "scan_today": kfqrcode.scan_today, "scan_total": kfqrcode.scan_total, "show_status": show_status };
                    kfqrcodeList.qrcode = '<a href="javascript:;" class="text-dark" onclick="showQrcodesImages(\'qrcode\',\'' + kfqrcode.img_url + '\',\'' + kfqrcode.name + '\');">查看</a>';
                    kfqrcodeList.method = '<div class="table-handdle"><a href="javascript:;" class="table-handdle-link" onclick="qrcodesListsImagesUpdate(\'' + kfqrcode.id + '\');">更新</a><a href="javascript:;" class="table-handdle-last text-danger" onclick=\'mviewNotification("error","子二维码删除提醒","子二维码删除后无法恢复,请确认是否删除？","确认删除","取消",{"type":"qecodedelete","qrcodes_id":"' + kfqrcode.id + '","key":"' + key + '"});\'>删除</a></div>';
                    kfqrcodeLists.push(kfqrcodeList);
                });
                var dataResult = {};
                dataResult.rows = kfqrcodeLists;
                dataResult.total = result.data.data.total;
                params.success(dataResult);
            } else {
                mviewToastr("error", result.msg);
            }
        },
        error: function(err) {
            mviewToastr("error", "网络异常,请联系客服处理！");
        }
    });
}

function getKfQrcodeStatus(kfqrcode) {
    if (kfqrcode.status != 1) return '<font class="text-warning">未上线</font>';
    var currentTime = moment().unix();
    if (currentTime >= kfqrcode.expiration_time) {
        return '<font class="text-warning">已过期</font>';
    } else {
        var limit_number = $("#limit_number").val();
        var switch_type = $("#switch").val();
        var limit_type = $("#limit_type").val();
        if (limit_type == 2) {
            if (limit_number == kfqrcode.scan_today) return '<font class="text-warning">今日访问上限</font>';
        } else {
            if (kfqrcode.scan_total > kfqrcode.count_limit) return '<font class="text-warning">累计访问上限</font>';
        }
    }
    return '<font class="text-success">上线中</font>';
}

function qrcodesListsAllImagesAdd(){
    $("#addallqrcodeModal").modal('toggle');
}

function jsUploadaa(max){
    $.each($("#upload_multiple_qrcode")['0'].files,function(index,val){
        if(imagearr.length+index < 10){
            uploadEach(index,val,max);
        }
    })
}

function uploadEach(index,val,max){
    var reader = new FileReader();
    reader.readAsDataURL(val);
    reader.onload = function (e) {
        var data = e.target.result;
        //加载图片获取图片真实宽度和高度
        var image = new Image();
        image.src = data;
        // 图片先加载完，才可以得到图片宽度和高度
        image.onload = function(){
            var width = image.width;
            var height = image.height;
            var pressParamas = {};
            if (width > 800) {
                pressParamas.width = 800;
            }
            if (val.size >= 1000000) {
                pressParamas.size = 300;
                pressParamas.quality = 0.8;
            } else if (val.size >= 500000) {
                pressParamas.size = 200;
                pressParamas.quality = 0.8;
            } else {
                pressParamas.size = 100;
                pressParamas.quality = 0.8;
            }
            var origin_type = val.type;
            if ($.inArray(origin_type,["image/png","image/webp"]) < 0) {
                pressParamas.type = val.type;
            } else {
                pressParamas.type = "image/jpeg";
            }
            imageConversion.compress(val,pressParamas).then(pressResult=>{
                var pressFile = blobToFile(pressResult,val.name,val.type);
                var oldSize = (val.size/1024).toFixed(0);
                var resultSize = (pressFile.size/1024).toFixed(0);
                if (resultSize > max) {
                    mviewToastr("error","图片压缩后不能超过"+max+"KB,当前为"+resultSize+"KB。");
                    return;
                }
                aliOssUploads(pressFile,'uploads',index);
            });
        }
    }
}

function aliOssUploads(file,dir,index){
    var randomId = generateRandomInteger(10000,99999);
    //获取上传的文件名，并得到文件后缀
    var point = file.name.lastIndexOf(".");
    var file_type = file.name.substr(point);//获取文件后缀
    var file_name_a = file.name.substr(0,point);//获取文件名称
    var day = getCurrentTime("day");
    var time = getCurrentTime("time");
    var imageName = randomId+file_type;
    var file_name = dir+"/"+day+"/"+time+randomId+file_type;
    //发送ajax请求我方php后端获取上传OSS时必要的参数信息
    $.ajax({
        type : "get", //提交方式
        url : "/api/version/1/oss/alioss_access_token",//路径
        data : {
            "dir" : dir
        },//数据，这里使用的是Json格式进行传输
        success : function(res) {//返回数据根据结果进行相应的处理
            res = JSON.parse(res);
            var imageurl = res.host+file_name;
            //上返回的参数使用formData中
            let formData = new FormData();
            formData.append('key', file_name);
            formData.append('OSSAccessKeyId', res.accessid);
            formData.append('policy', res.policy);
            formData.append('Signature', res.signature);
            formData.append('callback', res.callback);
            formData.append('success_action_status', 200); // 成功后返回的操作码
            formData.append('file', file);
            //接收到服务端返回的签名参数，开始通过另一个Ajax请求来上传文件到OSS
            //成功获取签名后上传文件到阿里云OSS
            $.ajax({
                type : "POST", //提交方式
                url : res.host,//路径
                dataType:'JSON',
                processData: false,
                cache: false,
                async: false,
                contentType: false,
                data : formData,
                success : function(result) {
                    if (result.Status == "Ok") {
                        if(imagearr.length < 30){
                            imagearr.push({"image":imageurl,"id":randomId,"name":file_name_a});
                            $("#image_arr").append('<div id="qrcode-item-'+randomId+'"><img src="'+imageurl+'" alt="'+file_name_a+'"><div onclick="deleteqrcode('+randomId+')"><icon class="iconfont icon-shanchu1"></icon></div></div>');
                        }
                    }
                },error:function(err){
                    mviewToastr("error","图片上传失败,请联系客服处理！");
                }
            });
        },error:function(err){
            mviewToastr("error","网络异常,请联系客服处理！");
        }
    });
}

function qrcodesImagesAddAllSubmit(){
    if (imagearr.length == 0) {
        mviewToastr("error", "请上传二维码!");
        return;
    }
    var qrcodes_name = $("#qrcodes_name").val();
    var expiration_time = $("#all_expiration_time").val();
    if (expiration_time == "") {
        mviewToastr("error", "请选择二维码有效期!");
        return;
    }
    var rate = $("#all_rate").val();
    if (rate == "") {
        mviewToastr("error", "请输入二维码权重!");
        return;
    }
    var count_limit = $("#all_count_limit").val();
    if (count_limit == "") {
        mviewToastr("error", "请输入二维码访问上限!");
        return;
    }
    var sign = $("#sign").val();
    var kfid = $("#kfid").val();
    var users_id = $("#users_id").val();
    $.ajax({
        url: "/admin/wxkf/wxkf_qrcodes_add",
        type: "POST",
        headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
        data: {
            "sign": sign,
            "kfid": kfid,
            "users_id": users_id,
            "qrcode": imagearr,
            "expiration_time": expiration_time,
            "rate": rate,
            "count_limit": count_limit,
        },
        success: function(res) {
            if (res.status == "success") {
                kfQrcodes = imagearr;
                qrcodeListReload();
                $("#addallqrcodeModal").modal('toggle');
                mviewToastr("success", res.msg);
                imagearr = [];
                $("#image_arr").empty();
            } else {
                mviewToastr("error", res.msg);
            }
        },
        error: function(err) {
            mviewToastr("error", "网络异常,请稍后重试！");
        }
    });
}

function qrcodesListsImagesUpdate(qrcodes_id) {
    var index = kfQrcodes.findIndex(qrcodesListsImage => {
        return qrcodesListsImage.id == qrcodes_id;
    });
    var qrcodeListImage = kfQrcodes[index];
    $("#qrcodeModal .modal-self-header h3").text("更新微信二维码");
    $("#qrcodeModal").modal('toggle');
    $("#qrcodes_id").val(qrcodes_id);
    $("#qrcode_show").attr("src", qrcodeListImage.img_url);
    $("#qrcode").val(qrcodeListImage.img_url);
    $("#qrcodes_name").val(qrcodeListImage.name);
    var expiration_time = moment(qrcodeListImage.expiration_time * 1000).format("YYYY-MM-DD");
    $("#expiration_time").val(expiration_time);
    $("#rate").val(qrcodeListImage.rate);
    $("#count_limit").val(qrcodeListImage.count_limit);
    $("#qrcodesModalButtonAdd").hide();
    $("#qrcodesModalButtonUpdate").show();
}

function kfqrcodesUpdateSubmit(){
    var qrcodes_name = $("#qrcodes_name").val();
    var expiration_time = $("#expiration_time").val();
    if (expiration_time == "") {
        mviewToastr("error", "请选择二维码有效期!");
        return;
    }
    var rate = $("#rate").val();
    if (rate == "") {
        mviewToastr("error", "请输入二维码权重!");
        return;
    }
    var count_limit = $("#count_limit").val();
    if (count_limit == "") {
        mviewToastr("error", "请输入二维码访问上限!");
        return;
    }
    var qrcode_name = $("#qrcodes_name").val();
    if (count_limit == "") {
        mviewToastr("error", "请输入二维码名称!");
        return;
    }
    var sign = $("#sign").val();
    var kfid = $("#kfid").val();
    var users_id = $("#users_id").val();
    var id = $("#qrcodes_id").val();
    $.ajax({
        url: "/admin/wxkf/wxkf_qrcodes_update",
        data: {
            "sign": sign,
            "kfid": kfid,
            "users_id": users_id,
            "id": id,
            "expiration_time": expiration_time,
            "rate": rate,
            "count_limit": count_limit,
            "qrcode_name":qrcode_name
        },
        success: function(res) {
            if (res.status == "success") {
                qrcodeListReload();
                $("#qrcodeModal").modal('toggle');
            }
            mviewToastr(res.status, res.msg);
        },
        error: function(err) {
            mviewToastr("error", "网络异常,请稍后重试！");
        }
    });  
}

function deleteKfQrcode(id){
    var sign = $("#sign").val();
    var kfid = $("#kfid").val();
    var users_id = $("#users_id").val();
    $.ajax({
        url: "/admin/wxkf/wxkf_qrcodes_delete",
        data: {
            "sign": sign,
            "kfid": kfid,
            "users_id": users_id,
            "id": id,
        },
        success: function(res) {
            if (res.status == "success") {
                qrcodeListReload();
            }
            mviewToastr(res.status, res.msg);
        },
        error: function(err) {
            mviewToastr("error", "网络异常,请稍后重试！");
        }
    });  
}

function statisticRecordDate(date) {
    $("#recordDatePickerRow li").removeClass("active");
    $("#recordDatePickerRow li[data=" + date + "]").addClass("active");
    if (date == "today") {
        $("#record_data_start").val(moment().format("YYYY-MM-DD"));
        $("#record_data_end").val(moment().format("YYYY-MM-DD 23:59:59"));
        $("#recordDatePicker").val(moment().format("YYYY-MM-DD") + " 至 " + moment().format("YYYY-MM-DD"));
    } else if (date == "yesterday") {
        $("#record_data_start").val(moment().subtract(1, "days").format("YYYY-MM-DD"));
        $("#record_data_end").val(moment().subtract(1, "days").format("YYYY-MM-DD 23:59:59"));
        $("#recordDatePicker").val(moment().subtract(1, "days").format("YYYY-MM-DD") + " 至 " + moment().subtract(1, "days").format("YYYY-MM-DD"));
    } else if (date == "threeday") {
        $("#record_data_start").val(moment().subtract(3, "days").format("YYYY-MM-DD"));
        $("#record_data_end").val(moment().format("YYYY-MM-DD 23:59:59"));
        $("#recordDatePicker").val(moment().subtract(3, "days").format("YYYY-MM-DD") + " 至 " + moment().format("YYYY-MM-DD"));
    } else if (date == "sevenday") {
        $("#record_data_start").val(moment().subtract(7, "days").format("YYYY-MM-DD"));
        $("#record_data_end").val(moment().format("YYYY-MM-DD 23:59:59"));
        $("#recordDatePicker").val(moment().subtract(7, "days").format("YYYY-MM-DD") + " 至 " + moment().format("YYYY-MM-DD"));
    } else {
        $("#record_data_start").val(moment().subtract(30, "days").format("YYYY-MM-DD"));
        $("#record_data_end").val(moment().format("YYYY-MM-DD 23:59:59"));
        $("#recordDatePicker").val(moment().subtract(30, "days").format("YYYY-MM-DD") + " 至 " + moment().format("YYYY-MM-DD"));
    }
    kfRecordReload();
}

function kfRecodeLists(params) {
    if(linkDetialLoad.record == 1){
        return;
    }
    params.data.start_time = $("#record_data_start").val();
    params.data.end_time = $("#record_data_end").val();
    params.data.kfid = $("#kfid").val();
    params.data.sign = $("#sign").val();
    params.data.qrcode_show_time = $("#qrcode-show").val();
    params.data.qrcode_press_time = $("#qrcode-press").val();
    params.data.qrcode_card_time = $("#qrcode-card").val();
    params.data.province = $("#province").val();
    params.data.code = $("#code").val();
    params.data.total = nextRecordData.total;
    params.data.total_end = nextRecordData.total_end;
    params.data.total_start = nextRecordData.total_start;
    $.ajax({
        url: "/admin/wxkf/wxkf_records",
        type: 'GET',
        data: params.data,
        dataType: 'json',
        success: function(result) {
            if (result.status == "success") {
                var qrRecordLists = [];
                kfRecordLists = result.data.data;
                $.each(result.data.data, function(key, item) {
                    var web_time = moment.unix(item.web_time).format("YYYY-MM-DD HH:mm:ss");
                    var click_time = item.click_time <= 1 ? '未点击' : '<font class="text-success">已点击</font>';
                    send_status_arr = ['','未发送','<font class="text-success">已发送</font>','<font class="text-error">发送失败</font>'];
                    var send_status = send_status_arr[item.send_status];
                    var qrcode_show_time = item.qrcode_show_time <= 1 ? '未展示' : '<font class="text-success">已展示</font>';
                    var qrcode_press_time = item.qrcode_press_time <= 1 ? '未长按' : '<font class="text-success">已长按</font>';
                    var qrcode_card_time = item.qrcode_card_time <= 1 ? '未点击' : '<font class="text-success">已点击</font>';
                    var name = item.name ? item.name : "-";
                    var code = (item.code == "") ? '-' : item.code;
                    var step_add = item.step_add > 1680000 ? '<font class="text-success">已添加</font>' : '-';
                    var browser = getRecordType(item.browser, "browser");
                    var system = getRecordType(item.system, "system");
                    var device = getRecordType(item.device, "device");
                    var model = getRecordType(item.model, "model");
                    var created_at = moment(item.created_at).format("YYYY-MM-DD HH:mm:ss");
                    var method = '<font class="text-primary" data-bs-toggle="offcanvas" href="#showRecordDetails" role="button" aria-controls="showRecordDetails" onclick="showRecordDetails(\'' + item.record_id + '\')">详情</font>';
                    var qrRecordList = { "province": item.province, "city": item.city, "ip": item.ip, "system": system, "code": code, "device": device, "model": item.model, "name": name, "web_time": web_time, "click_time": click_time,"send_status": send_status,"qrcode_show_time": qrcode_show_time, "qrcode_press_time": qrcode_press_time, "qrcode_card_time": qrcode_card_time, "browser": browser, "created_at": created_at, "method": method };
                    qrRecordLists.push(qrRecordList);
                });
                if (result.data.total_end !== undefined) {
                    nextRecordData = { "total": result.data.total, "total_end": result.data.total_end, "total_start": result.data.total_start };
                }
                var dataResult = {};
                dataResult.rows = qrRecordLists;
                dataResult.total = result.data.total;
                params.success(dataResult);
            } else {
                mviewToastr("error", result.msg);
            }
        }
    });
}
//清空选项
function kfRecordEmpty() {
    var emarr = ['#code','#province','#qrcode-show','#qrcode-press','#qrcode-card'];
    $.each(emarr, function(index, val) {
        value = index < 2 ? "" : 0;
        $(val).val(value);
    });
}

function showRecordDetails(record_id) {
    $("#qrcodeRecordTime").html("");
    var index = kfRecordLists.findIndex(linkRecordList => {
        return linkRecordList.record_id == record_id;
    });
    var linkRecord = kfRecordLists[index];
    $("#recodeQrcodeImage").attr("src", linkRecord.img_url);
    $("#qrcodeshow").show();
    if (linkRecord.web_time > 1) {
        $("#qrcodeRecordTime").append("<tr><td>访问落地页</td><td>" + moment(linkRecord.web_time * 1000).format("YYYY-MM-DD HH:mm:ss") + "</td></tr>");
    } else {
        $("#qrcodeRecordTime").append("<tr><td>访问落地页</td><td>未访问</td></tr>");
    }
    if (linkRecord.click_time > 1) {
        $("#qrcodeRecordTime").append("<tr><td>跳转按钮点击</td><td>" + moment(linkRecord.click_time * 1000).format("YYYY-MM-DD HH:mm:ss") + "</td></tr>");
    } else {
        $("#qrcodeRecordTime").append("<tr><td>跳转按钮点击</td><td>未点击</td></tr>");
    }
    if (linkRecord.kefu_time > 1) {
        $("#qrcodeRecordTime").append("<tr><td>客服发送欢迎语时间</td><td>" + moment(linkRecord.kefu_time * 1000).format("YYYY-MM-DD HH:mm:ss") + "</td></tr>");
    } else {
        $("#qrcodeRecordTime").append("<tr><td>发送欢迎语</td><td>未发送欢迎语</td></tr>");
    }
    if (linkRecord.qrcode_show_time > 1) {
        $("#qrcodeRecordTime").append("<tr><td>二维码展示时间</td><td>" + moment(linkRecord.qrcode_show_time * 1000).format("YYYY-MM-DD HH:mm:ss") + "</td></tr>");
    } else {
        $("#qrcodeRecordTime").append("<tr><td>二维码展示时间</td><td>未展示</td></tr>");
    }
    if (linkRecord.qrcode_press_time > 1) {
        $("#qrcodeRecordTime").append("<tr><td>长按识别时间</td><td>" + moment(linkRecord.qrcode_press_time * 1000).format("YYYY-MM-DD HH:mm:ss") + "</td></tr>");
    } else {
        $("#qrcodeRecordTime").append("<tr><td>长按识别时间</td><td>未长按</td></tr>");
    }
    if (linkRecord.qrcode_card_time > 1) {
        $("#qrcodeRecordTime").append("<tr><td>点击名片时间</td><td>" + moment(linkRecord.qrcode_card_time * 1000).format("YYYY-MM-DD HH:mm:ss") + "</td></tr>");
    } else {
        $("#qrcodeRecordTime").append("<tr><td>点击名片时间</td><td>未点击</td></tr>");
    }
    if (linkRecord.qrcode_add_time > 1) {
        $("#qrcodeRecordTime").append("<tr><td>添加时间</td><td>" + moment(linkRecord.qrcode_add_time * 1000).format("YYYY-MM-DD HH:mm:ss") + "</td></tr>");
    } else {
        $("#qrcodeRecordTime").append("<tr><td>添加时间</td><td>未添加</td></tr</td></tr>");
    }
}

// 访问数据记录
function kfListsData() {
    if (linkDetialLoad.chart == 1) {
        return;
    }
    var chartDom = document.getElementById('overview-chart');
    var myChart = echarts.init(chartDom);
    myChart.clear();
    var kfid = $("#kfid").val();
    var statistics_start = $("#statistics_start").val();
    var statistics_end = $("#statistics_end").val();
    var users_id = $("#users_id").val();
    var platfrom_type = parseInt($("#platfrom_type").val());
    $.ajax({
        url: "/admin/wxkf/wxkf_statistic",
        type: 'GET',
        data: {
            "kfid": kfid,
            "date_start": statistics_start,
            "date_end": statistics_end,
            "users_id": users_id,
        },
        success: function(result) {
            if (result.status == "success") {
                var datakey = [];
                var web = [];
                var click = [];
                var kefu = [];
                var qrcode_show = [];
                var qrcode_press = [];
                var qrcode_card = [];
                var qrcode_add = [];
                $.each(result.data.statistics, function(idx, data) {
                    datakey.push(moment(data.phase, "YYYY-MM-DD").format("MM月DD日"));
                    web.push(data.web);
                    click.push(data.click);
                    kefu.push(data.kefu);
                    qrcode_show.push(data.qrcode_show);
                    qrcode_press.push(data.qrcode_press);
                    qrcode_card.push(data.qrcode_card);
                    qrcode_add.push(data.qrcode_add);
                });
                var dataKeyLists = ['链接访问量', '跳客服按钮点击', '发送欢迎语', '二维码展示', '长按识别', '点击名片', '添加好友'];
                var seriesLists = [
                        { name: '链接访问量', type: 'line', areaStyle: { color: '#556ee6', opacity: 0.1 }, smooth: true, data: web }, 
                        { name: '跳客服按钮点击', type: 'line', smooth: true, data: click, }, 
                        { name: '发送欢迎语', type: 'line', smooth: true, data: kefu, }, 
                        { name: '二维码展示', type: 'line', smooth: true, data: qrcode_show }, 
                        { name: '长按识别', type: 'line', smooth: true, data: qrcode_press },
                        { name: '点击名片', type: 'line', smooth: true, data: qrcode_card },
                        { name: '添加好友', type: 'line', smooth: true, data: qrcode_add },
                    ]
                var option = {
                    color: ['#5470c6', '#91cc75', '#fac858', '#ee6666', '#73c0de', '#3ba272', '#fc8452', '#9a60b4', '#ea7ccc'],
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'cross',
                            label: {
                                backgroundColor: '#6a7985',
                                precision: 0
                            }
                        }
                    },
                    legend: {
                        data: dataKeyLists
                    },
                    toolbox: {
                        feature: {
                            dataView: {
                                show: true,
                                title: '数据视图',
                                lang: ['数据视图', '关闭', '导出Excel'],
                                contentToOption: function(opts) {
                                    $("#tableExcel_Day").table2excel({
                                        exclude: ".noExl",
                                        filename: '访问数据',
                                        name: "Excel Document Name.xls",
                                        exclude_img: true,
                                        exclude_links: true,
                                        exclude_inputs: true
                                    });
                                },
                                optionToContent: function(opt) {
                                    var axisData = opt.xAxis[0].data; //坐标数据
                                    var series = opt.series; //折线图数据
                                    var tdHeads = '<td style="height: 30px;line-height:30px;">日期/时间</td>'; //表头第一列
                                    var tdBodys = ''; //表数据
                                    //组装表头
                                    for (var i = 0; i < dataKeyLists.length; i++) {
                                        tdHeads += '<td style="height: 30px;line-height:30px;">' + dataKeyLists[i] + '</td>';
                                    }
                                    var table = '<table id="tableExcel_Day" border="1" class="table-bordered table-striped" style="width:100%;text-align:center" ><tbody><tr>' + tdHeads + ' </tr>';
                                    //组装表数据
                                    for (var i = 0, l = axisData.length; i < l; i++) {
                                        for (var j = 0; j < series.length; j++) {
                                            var temp = series[j].data[i];
                                            if (temp != null && temp != undefined) {
                                                tdBodys += '<td>' + temp.toFixed(0) + '</td>';
                                            } else {
                                                tdBodys += '<td></td>';
                                            }
                                        }
                                        table += '<tr><td style="height: 30px;line-height:30px;">' + axisData[i] + '</td>' + tdBodys + '</tr>';
                                        tdBodys = '';
                                    }
                                    table += '</tbody></table>';
                                    return table;
                                }
                            },
                            saveAsImage: {
                                type: 'png',
                                title: '下载访问数据',
                                name: '访问数据'
                            }
                        }
                    },
                    grid: {
                        left: '0%',
                        right: '4%',
                        bottom: '0%',
                        containLabel: true
                    },
                    xAxis: [{
                        type: 'category',
                        boundaryGap: false,
                        data: datakey
                    }],
                    yAxis: [{
                        min: 0,
                        type: 'value',
                    }],
                    series: seriesLists
                };
                option && myChart.setOption(option);
            } else {
                mviewToastr("error", result.msg);
            }
        },
        error: function(err) {
            mviewToastr("error", "网络异常,请联系客服处理！");
        }
    });
}

function renderRecordExportTime(value) {
    if (value == "today") {
        var start = moment().format("YYYY-MM-DD");
        var end = moment().format("YYYY-MM-DD") + " 23:59:59";
    } else if (value == "yesterday") {
        var start = moment().subtract(1, "days").format("YYYY-MM-DD");
        var end = moment().subtract(1, "days").format("YYYY-MM-DD") + " 23:59:59";
    } else if (value == "thismonth") {
        var start = moment().startOf("month").format("YYYY-MM-DD");
        var end = moment().endOf("month").format("YYYY-MM-DD");
    } else if (value == "lastmonth") {
        var start = moment().subtract(1, "months").startOf("month").format("YYYY-MM-DD");
        var end = moment().subtract(1, "months").endOf("month").format("YYYY-MM-DD");
    }
    $("#record_export_start").val(start);
    $("#record_export_end").val(end);
    $("#recordExportDatePicker").val(start+" 至 "+end);
}

function getRecordType(key, type) {
    if (type == "system") {
        var arr = ["-", "安卓", "苹果", "Win", "Mac"]
        try {
            return arr[key];
        } catch (e) {
            return '-';
        }
    } else if (type == "device") {
        var arr = ["其他", "华为", "Vivo", "小米", "OPPO", "三星", "苹果"];
        try {
            return arr[key];
        } catch (e) {
            return '-';
        }
    } else if (type == "qrcode") {
        var index = linkQrcodes.findIndex(linkQrcode => {
            return linkQrcode.qrcodes_id == key;
        });
        if (index >= 0) {
            return linkQrcodes[index].name;
        } else {
            return '-';
        }
    } else {
        var browsers = ["", "微信浏览器", "电脑QQ浏览器", "Vivo浏览器", "Oppo浏览器", "华为浏览器", "小米浏览器", "QQ浏览器", "支付宝浏览器", "百度APP", "微博浏览器", "爱奇艺浏览器", "小米浏览器", "喜马拉雅", "钉钉", "UC浏览器", "三星浏览器", "诺基亚浏览器", "欧朋", "火狐", "知乎", "飞书", "Iphone", "Ipad", "苹果电脑", "其他浏览器", "抖音APP", "抖音极速版", "抖音火山版", "今日头条", "今日头条极速版", "西瓜视频", "番茄小说", "百度极速版", "百度贴吧", "API调用"];
        try {
            return browsers[key];
        } catch (e) {
            return '-----';
        }
    }
}

function statisticsDate(date) {
    $("#statisticChartDate li").removeClass("active");
    $("#statisticsDate_" + date).addClass("active");
    if (date == "threeday") {
        $("#statistics_start").val(moment().subtract(3, "days").format("YYYY-MM-DD"));
        $("#statistics_end").val(moment().subtract(1, "days").format("YYYY-MM-DD 23:59:59"));
        $("#statistics_day").val(2);
        $("#statisticsdate").val(moment().subtract(3, "days").format("YYYY-MM-DD") + " 至 " + moment().subtract(1, "days").format("YYYY-MM-DD"));
    } else {
        $("#statistics_start").val(moment().subtract(7, "days").format("YYYY-MM-DD"));
        $("#statistics_end").val(moment().subtract(1, "days").format("YYYY-MM-DD 23:59:59"));
        $("#statistics_day").val(6);
        $("#statisticsdate").val(moment().subtract(7, "days").format("YYYY-MM-DD") + " 至 " + moment().subtract(1, "days").format("YYYY-MM-DD"));
    }
    kfListsData();
}

function renderOtherData(status) {
    if (status == "today") {
        $("#other_date_start").val(moment().format("YYYY-MM-DD"));
        $("#other_date_end").val(moment().format("YYYY-MM-DD") + " 23:59:59");
    } else if (status == "yesterday") {
        $("#other_date_start").val(moment().subtract(1, "days").format("YYYY-MM-DD"));
        $("#other_date_end").val(moment().subtract(1, "days").format("YYYY-MM-DD") + " 23:59:59");
    } else if (status == "thismonth") {
        $("#other_date_start").val(moment().startOf("month").format("YYYY-MM-DD"));
        $("#other_date_end").val(moment().endOf("month").format("YYYY-MM-DD"));
    } else if (status == "lastmonth") {
        $("#other_date_start").val(moment().subtract(1, "months").startOf("month").format("YYYY-MM-DD"));
        $("#other_date_end").val(moment().subtract(1, "months").endOf("month").format("YYYY-MM-DD"));
    }
    renderOtherChart();
}

// 获取小程序其他数据统计
function renderOtherChart() {
    if (linkDetialLoad.other == 1) {
        return;
    }
    $("#custom_loading").show();
    var kfid = $("#kfid").val();
    var users_id = $("#users_id").val();
    var other_date_start = $("#other_date_start").val();
    var other_date_end = $("#other_date_end").val();
    var other_chart = $("#other_chart").val();
    var diff_day = moment(other_date_end).diff(moment(other_date_start), "days");
    $.ajax({
        url: "/admin/wxkf/wxkf_other_statistic",
        data: {
            "kfid": kfid,
            "users_id": users_id,
            "other_date_start": other_date_start,
            "other_date_end": other_date_end,
            "other_chart": other_chart,
            "diff_day": diff_day,
        },
        success: function(result) {
            if (result.status == "error") {
                mviewToastr("error", result.msg);
            } else {
                var text = "";
                var subtext = "";
                if (other_chart == "rate") {
                    otherRateChart(result.data.datas,diff_day);
                } else if (other_chart == "map") {
                    getLinksMap(result.data.datas);
                } else {
                    otherPieChart(result.data.datas);
                }
                $("#custom_loading").hide();
            }
        },
        error: function(error) {
            mviewToastr("error", "请求失败,请联系客服处理!");
        }
    });
}

function otherPieChart(datas) {
    var chartDom = document.getElementById('otherchart');
    var myChart = echarts.init(chartDom);
    myChart.clear();
    var dataLists = [];
    var colorLists = ['#5470c6', '#91cc75', '#fac858', '#ee6666', '#73c0de', '#3ba272', '#fc8452', '#9a60b4', '#ea7ccc'];
    $.each(datas, function(index, dataList) {
        dataLists.push({ "name": dataList.name, "value": dataList.value, "itemStyle": { "color": colorLists[index] } });
    });
    var other_chart = $("#other_chart").val();
    if (other_chart == "system") {
        var text = "操作系统";
        var subtext = "客户使用什么操作系统访问落地页";
    } else if (other_chart == "browser") {
        var text = "访问环境";
        var subtext = "链接通过什么浏览器/APP访问落地页";
    } else {
        var text = "设备类型";
        var subtext = "客户使用什么手机访问落地页";
    }
    var option = {
        title: {
            text: text,
            subtext: subtext,
            left: 'center'
        },
        tooltip: {
            trigger: 'item'
        },
        legend: {
            orient: 'vertical',
            left: 'left'
        },
        series: [{
            name: '访问数据',
            type: 'pie',
            radius: '50%',
            data: dataLists,
            emphasis: {
                itemStyle: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }]
    };
    option && myChart.setOption(option);
    myChart.resize();
}

function otherRateChart(datas,diff_day) {
    var dataLists = [];
    var colorLists = ['#5470c6', '#91cc75', '#fac858', '#ee6666', '#73c0de', '#3ba272', '#fc8452', '#9a60b4', '#ea7ccc'];
    if (datas[0].value <= 0) {
        var subtext = "当前暂无转化数据";
    } else {
        if (diff_day > 1) {
            var subtext = "按月查询暂不统计当日数据";
        } else {
            var subtext = "跳转客服是指点击了链接里的跳转客服按钮";
        }
    }
    $.each(datas,function(index, dataList) {
        if(dataList.name != '跳转按钮'){
            dataLists.push({ "name": dataList.name, "value": dataList.value, "itemStyle": { "color": colorLists[index] } });
        }
    });
    var option = {
        title: {
            text: '转化率',
            subtext: subtext,
            x: 'center'
        },
        tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b} : {c}%'
        },
        toolbox: {
            feature: {
                dataView: { readOnly: false },
                restore: {},
                saveAsImage: {}
            }
        },
        legend: {
            data: ['访问落地页', '发送欢迎语','二维码展示', '二维码长按', '点击名片'],
            left : '20',
            orient: 'vertical'
        },
        series: [{
            name: '转化率',
            type: 'funnel',
            left: '10%',
            top: 60,
            bottom: 60,
            width: '80%',
            min: 0,
            max: 100,
            minSize: '0%',
            maxSize: '100%',
            gap: 5,
            label: {
                show: true,
                position: 'inside'
            },
            labelLine: {
                length: 10,
                lineStyle: {
                    width: 1,
                    type: 'solid'
                }
            },
            itemStyle: {
                borderColor: '#fff',
                borderWidth: 1
            },
            emphasis: {
                label: {
                    fontSize: 20
                }
            },
            data: dataLists
        }]
    };
    var myChart = echarts.init(document.getElementById('otherchart'));
    myChart.clear();
    myChart.setOption(option);
    myChart.resize();
    $("#custom_loading").hide();
}

function getLinksMap(datas) {
    var provinceLists = [];
    $.each(datas, function(key, provinceList) {
        var name = provinceList.name.replace("省", "").replace("市", "");
        provinceLists.push({ "name": name, "value": provinceList.value });
    });
    var optionMap = {
        backgroundColor: '#FFFFFF',
        title: {
            text: '全国地图大数据',
            subtext: '海外地区目前无法在地图中显示',
            x: 'center'
        },
        tooltip: {
            trigger: 'item'
        },
        visualMap: {
            show: false,
        },
        series: [{
            name: '访问用户',
            type: 'map',
            mapType: 'china',
            roam: true,
            label: {
                normal: {
                    show: true
                },
                emphasis: {
                    show: false
                }
            },
            data: provinceLists
        }]
    };
    //初始化echarts实例
    var myChart = echarts.init(document.getElementById('otherchart'));
    myChart.clear();
    //使用制定的配置项和数据显示图表
    myChart.setOption(optionMap);
    myChart.resize();
    $("#custom_loading").hide();
}

function showQrcodesImages(type, img_url, name) {
    $("#serviceModal").modal('toggle');
    $("#service_qrcode").attr("src", img_url);
    $("#service_text").text(name);
    $("#service_time").hide();
    $("#service_describe").text("如果需要下载二维码,请使用鼠标右键点击图片下载");
}

function deleteqrcode(id){
    imagearr = imagearr.filter(item=>item.id != id);
    $("#qrcode-item-"+id).remove();
}
